// 将来，需要在这里创建 Store

// 1. 导入创建 Store 的函数
import { configureStore, combineReducers } from '@reduxjs/toolkit'
// 4. 导入需要的切片中的 reducer
import ticketReducer from './slice/ticketSlice'
import userReducer from './slice/userSlice'
import orderReducer from './slice/orderSlice'
// 配置 store 数据的持久化存储
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

const persistConfig = {
  key: 'root',
  storage,
  // 黑名单，被记录到黑名单中的 Slice 切片，不会被持久化存储到本地
  blacklist: ['order']
}

const persistedReducer = persistReducer(
  persistConfig,
  // 挂载切片
  combineReducers({
    ticket: ticketReducer,
    user: userReducer,
    order: orderReducer
  })
)

// 2. 调用步骤1的函数，创建 Store
const store = configureStore({
  reducer: persistedReducer,
  middleware: (m) => m({ serializableCheck: false })
})

export let persistor = persistStore(store)

// 3. 导出 Store
export default store
